// 正式开发地址
const BASEURL = 'http://kumanxuan1.f3322.net:8001';


export function fetch(url, data = {}, headers = {}, method = "POST") {
	return new Promise((resolve, resject) => {
		uni.request({
			url: BASEURL + url,
			data: data,
			method: method,
			headers: headers,
			dataType: 'json',
			responseType: 'json',
			success(res) {
				if (res.data.errno != 0) {
					uni.showToast({
						title: res.data.errmsg ?? '请求失败',
						icon: 'error'
					});
					resject(res.data.errmsg ?? '请求失败')
				} else {
					resolve(res.data)
				}
			},
			fail() {
				resject(null)
			}
		})
	})
}
